
public class ASTTreeNode {

	/*
	 * type is -1 to imply uninitialized, only token == 0, implies that it is <ID>, needed by ST 
	 */
	String content;
	ASTTreeNode childArray[];
	int type = -1;
	boolean terminal = false;
	
	public ASTTreeNode(String text, int numLinks){
		content = text;
		childArray = new ASTTreeNode[numLinks];
	}

	public void assignChild(int childNum, ASTTreeNode astNode){
		childArray[childNum] = astNode;
	}
	
	public void print(int numDots){
		String dots = "";
		for(int i = 0; i < numDots ; i++){
			dots += '.';
		}
		System.out.println(dots + content);
		for(int i = 0; i < childArray.length ; i++){
			childArray[i].print(numDots+1);
		}
	}
	
	/*
	 * let
	.=
	..<ID:sd>
	..where
	...<ID:A>
	...function_form
	....<ID:A>
	....<ID:n>
	....<INT:4>
	.gamma
	..<ID:print>
	..gamma
	...<ID:sd>
	...<INT:2>
	 */
	public static void main(String[] args) {
		ASTTreeNode a1 = new ASTTreeNode("let", 2);
		ASTTreeNode a2 = new ASTTreeNode("=", 2);
		ASTTreeNode a3 = new ASTTreeNode("<ID:sd>", 0);
		ASTTreeNode a4 = new ASTTreeNode("where", 2);
		ASTTreeNode a5 = new ASTTreeNode("<ID:A>", 0);
		ASTTreeNode a6 = new ASTTreeNode("function_form", 3);
		ASTTreeNode a7 = new ASTTreeNode("<ID:A>", 0);
		ASTTreeNode a8 = new ASTTreeNode("<ID:n>", 0);
		ASTTreeNode a9 = new ASTTreeNode("<ID:4>", 0);
		ASTTreeNode a10 = new ASTTreeNode("gamma", 2);
		ASTTreeNode a11 = new ASTTreeNode("<ID:print>", 0);
		ASTTreeNode a12 = new ASTTreeNode("gamma", 2);
		ASTTreeNode a13 = new ASTTreeNode("<ID:sd>", 0);
		ASTTreeNode a14 = new ASTTreeNode("<ID:2>", 0);
		
		a1.childArray[0] = a2;
		a1.childArray[1] = a10;
		a2.childArray[0] = a3;
		a2.childArray[1] = a4;
		a4.childArray[0] = a5;
		a4.childArray[1] = a6;
		a6.childArray[0] = a7;
		a6.childArray[1] = a8;
		a6.childArray[2] = a9;
		a10.childArray[0] = a11;
		a10.childArray[1] = a12;
		a12.childArray[0] = a13;
		a12.childArray[1] = a14;
		
		a1.print(0);
	}

	@Override
	public String toString() {
		return "ASTTreeNode [content=" + content + ", type=" + type
				+ ", terminal=" + terminal + "]";
	}

}
